import React from 'react'

export default class Add extends React.Component {
  render() {
    return <div>
      <input type="text" ref="user"/>
      <input type="text" ref="content"/>
      <input type="button" value="添加" onClick={()=>this.addData()}/>
    </div>
  }

  addData = () => {
    if (this.refs.user.value.trim() === '' || this.refs.content.value.trim() === '' ){
      return alert('填写完整内容')
    }
    this.props.addFn({
      user: this.refs.user.value,
      content: this.refs.content.value,
      id: Math.random()
    })

    this.refs.user.value = this.refs.content.value = ''
  }
}